package 题目集.树.遍历模拟;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

//https://pintia.cn/problem-sets/1745272598755459072/exam/problems/1745606572212137994?type=7&page=0
public class 这是二叉搜索树吗 {
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n = sc.nextInt();
        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        Tree root = builder(arr);
        StringBuilder builder=new StringBuilder();
        if (isBST(root,arr)||(index=0)==1){
            print(root, builder);
        }else if (isBST2(root,arr)) {
            print2(root, builder);
        }else {
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
        builder.deleteCharAt(builder.length()-1);
        System.out.println(builder.toString());
    }
    public static Tree builder(int[] arr){
        Tree root=new Tree(arr[0]);
        for (int i = 1; i < arr.length; i++) {
            Tree cur=root;
            Tree parent=cur;
            while (cur!=null){
                parent=cur;
                if (cur.val>arr[i]){
                    cur=cur.left;
                }else {
                    cur=cur.right;
                }
            }
            if (parent.val>arr[i]) {
                parent.left = new Tree(arr[i]);
            }else {
                parent.right=new Tree(arr[i]);
            }
        }
        return root;
    }
    static int index=0;

    /**
     * 中左右遍历判断是否相同
     */
    public static boolean isBST(Tree root,int[] preorder){
        if (root==null){
            return true;
        }
        if (root.val!=preorder[index]){
            return false;
        }
        index++;
        return isBST(root.left,preorder)&&isBST(root.right,preorder);
    }

    /**
     * 中右左判断
     */
    public static boolean isBST2(Tree root,int[] preorder){
        if (root==null){
            return true;
        }
        if (root.val!=preorder[index]){
            return false;
        }
        index++;
        return isBST2(root.right,preorder)&&isBST2(root.left,preorder);
    }
    //左右中遍历
    public static void print(Tree root,StringBuilder builder) {
        if (root == null) {
            return;
        }
        print(root.left,builder);
        print(root.right,builder);
        builder.append(root.val).append(" ");
    }
    //右左中遍历
    public static void print2(Tree root,StringBuilder builder) {
        if (root == null) {
            return;
        }
        print2(root.right,builder);
        print2(root.left,builder);
        builder.append(root.val).append(" ");
    }


    static class Tree{
        int val;
        Tree left;
        Tree right;

        public Tree(int val) {
            this.val = val;
        }
    }
    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}

